#!/usr/bin/env python
#-*- coding:utf-8 -*-

"""
	PROJECT pyevocomm -

	APP		socket server controller

	MODULE	server for controller

	SITE DESCRIPTION http://code.google.com/p/pyevocomm/ 

	@copyright: 2012 by archetipo <alessio.gerace@gmail.com>
	@license: New BSD License, see COPYING for details.
"""

from socket import *
import json
import threading

# We'll pickle a list of numbers:


# Our thread class:
class ThController( threading.Thread ):

   # Override Thread's __init__ method to accept the parameters needed:
	def __init__( self,parent):
		print 'Inizzializzazione server controller'
		self.porta = 4001
		self.server = socket(AF_INET, SOCK_STREAM)
		self.server.bind(('19.61.1.1', self.porta))
		self.server.listen(5)
		self.parent = parent
		threading.Thread.__init__ ( self )

	def run ( self ):
		while True:
			connection, address = self.server.accept()
			data = connection.recv(1024)
			j=json.loads(data)
			self.parent.recdata(j)

# Set up the server:


# Have the server serve "forever":


#~ class test():
	#~ def __init__(self):
		#~ self.data=None
		#~ ThController(self).start()
	#~ def recdata(self,val):
		#~ self.data=val
		#~ print self.data
#~ t=test()

